import numpy as np
import tensorflow.compat.v2 as tf
tf.enable_v2_behavior()
import pandas as pd
from tensorflow import keras
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import RobustScaler
from sklearn.preprocessing import MinMaxScaler
from matplotlib import pyplot
import plotly.graph_objects as go
import math
import seaborn as sns
from sklearn.metrics import mean_squared_error
np.random.seed(1)
tf.random.set_seed(1)
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM, GRU, Dropout, RepeatVector, TimeDistributed
from keras import backend
MODELFILENAME = 'MODELS/LSTM_12h_TFM'
TIME_STEPS=72 #12h
CMODEL = LSTM
UNITS=40
DROPOUT=0.405
ACTIVATION='tanh'
OPTIMIZER='adam'
EPOCHS=40
BATCHSIZE=45
VALIDATIONSPLIT=0.1
# Code to read csv file into Colaboratory:
# from google.colab import files
# uploaded = files.upload()
# import io
# df = pd.read_csv(io.BytesIO(uploaded['SentDATA.csv']))
# Dataset is now stored in a Pandas Dataframe
df = pd.read_csv('../../data/dadesTFM.csv')
df.reset_index(inplace=True)
df['Time'] = pd.to_datetime(df['Time'])
df = df.set_index('Time')
columns = ['PM1','PM25','PM10','PM1ATM','PM25ATM','PM10ATM']
df1 = df.copy();
df1 = df1.rename(columns={"PM 1":"PM1","PM 2.5":"PM25","PM 10":"PM10","PM 1 ATM":"PM1ATM","PM 2.5 ATM":"PM25ATM","PM 10 ATM":"PM10ATM"})
df1['PM1'] = df['PM 1'].astype(np.float32)
df1['PM25'] = df['PM 2.5'].astype(np.float32)
df1['PM10'] = df['PM 10'].astype(np.float32)
df1['PM1ATM'] = df['PM 1 ATM'].astype(np.float32)
df1['PM25ATM'] = df['PM 2.5 ATM'].astype(np.float32)
df1['PM10ATM'] = df['PM 10 ATM'].astype(np.float32)
df2 = df1.copy()
train_size = int(len(df2) * 0.8)
test_size = len(df2) - train_size
train, test = df2.iloc[0:train_size], df2.iloc[train_size:len(df2)]
train.shape, test.shape
((3117, 7), (780, 7))
#Standardize the data
for col in columns:
scaler = StandardScaler()
train[col] = scaler.fit_transform(train[[col]])
<ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]])
def create_sequences(X, y, time_steps=TIME_STEPS):
Xs, ys = [], []
for i in range(len(X)-time_steps):
Xs.append(X.iloc[i:(i+time_steps)].values)
ys.append(y.iloc[i+time_steps])
return np.array(Xs), np.array(ys)
X_train, y_train = create_sequences(train[[columns[1]]], train[columns[1]])
#X_test, y_test = create_sequences(test[[columns[1]]], test[columns[1]])
print(f'X_train shape: {X_train.shape}')
print(f'y_train shape: {y_train.shape}')
X_train shape: (3045, 72, 1) y_train shape: (3045,)
#afegir nova mètrica
def rmse(y_true, y_pred):
return backend.sqrt(backend.mean(backend.square(y_pred - y_true), axis=-1))
model = Sequential()
model.add(CMODEL(units = UNITS, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))
model.add(Dropout(rate=DROPOUT))
model.add(TimeDistributed(Dense(1,kernel_initializer='normal',activation=ACTIVATION)))
model.compile(optimizer=OPTIMIZER, loss='mae',metrics=['mse',rmse])
model.summary()
Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= lstm (LSTM) (None, 72, 40) 6720 _________________________________________________________________ dropout (Dropout) (None, 72, 40) 0 _________________________________________________________________ time_distributed (TimeDistri (None, 72, 1) 41 ================================================================= Total params: 6,761 Trainable params: 6,761 Non-trainable params: 0 _________________________________________________________________
history = model.fit(X_train, y_train, epochs=EPOCHS, batch_size=BATCHSIZE, validation_split=VALIDATIONSPLIT,
callbacks=[keras.callbacks.EarlyStopping(monitor='val_loss', patience=5, mode='min')], shuffle=False)
Epoch 1/40 61/61 [==============================] - 2s 27ms/step - loss: 0.7256 - mse: 0.9013 - rmse: 0.7335 - val_loss: 0.4481 - val_mse: 0.2363 - val_rmse: 0.4669 Epoch 2/40 61/61 [==============================] - 1s 19ms/step - loss: 0.6093 - mse: 0.6799 - rmse: 0.6435 - val_loss: 0.3260 - val_mse: 0.1415 - val_rmse: 0.3562 Epoch 3/40 61/61 [==============================] - 1s 19ms/step - loss: 0.5957 - mse: 0.6653 - rmse: 0.6379 - val_loss: 0.2948 - val_mse: 0.1210 - val_rmse: 0.3264 Epoch 4/40 61/61 [==============================] - 1s 19ms/step - loss: 0.5845 - mse: 0.6498 - rmse: 0.6314 - val_loss: 0.2715 - val_mse: 0.1070 - val_rmse: 0.3043 Epoch 5/40 61/61 [==============================] - 1s 20ms/step - loss: 0.5764 - mse: 0.6417 - rmse: 0.6278 - val_loss: 0.2526 - val_mse: 0.0966 - val_rmse: 0.2867 Epoch 6/40 61/61 [==============================] - 2s 26ms/step - loss: 0.5709 - mse: 0.6366 - rmse: 0.6258 - val_loss: 0.2411 - val_mse: 0.0904 - val_rmse: 0.2753 Epoch 7/40 61/61 [==============================] - 1s 22ms/step - loss: 0.5677 - mse: 0.6335 - rmse: 0.6251 - val_loss: 0.2337 - val_mse: 0.0864 - val_rmse: 0.2677 Epoch 8/40 61/61 [==============================] - 1s 23ms/step - loss: 0.5651 - mse: 0.6309 - rmse: 0.6242 - val_loss: 0.2293 - val_mse: 0.0841 - val_rmse: 0.2629 Epoch 9/40 61/61 [==============================] - 1s 22ms/step - loss: 0.5628 - mse: 0.6282 - rmse: 0.6231 - val_loss: 0.2246 - val_mse: 0.0818 - val_rmse: 0.2581 Epoch 10/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5614 - mse: 0.6266 - rmse: 0.6226 - val_loss: 0.2219 - val_mse: 0.0804 - val_rmse: 0.2551 Epoch 11/40 61/61 [==============================] - 1s 23ms/step - loss: 0.5596 - mse: 0.6250 - rmse: 0.6218 - val_loss: 0.2172 - val_mse: 0.0783 - val_rmse: 0.2504 Epoch 12/40 61/61 [==============================] - 2s 25ms/step - loss: 0.5590 - mse: 0.6241 - rmse: 0.6216 - val_loss: 0.2163 - val_mse: 0.0778 - val_rmse: 0.2490 Epoch 13/40 61/61 [==============================] - 1s 23ms/step - loss: 0.5579 - mse: 0.6228 - rmse: 0.6210 - val_loss: 0.2143 - val_mse: 0.0768 - val_rmse: 0.2467 Epoch 14/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5572 - mse: 0.6222 - rmse: 0.6207 - val_loss: 0.2126 - val_mse: 0.0761 - val_rmse: 0.2448 Epoch 15/40 61/61 [==============================] - 2s 25ms/step - loss: 0.5568 - mse: 0.6214 - rmse: 0.6204 - val_loss: 0.2119 - val_mse: 0.0757 - val_rmse: 0.2437 Epoch 16/40 61/61 [==============================] - 1s 25ms/step - loss: 0.5559 - mse: 0.6203 - rmse: 0.6199 - val_loss: 0.2103 - val_mse: 0.0750 - val_rmse: 0.2419 Epoch 17/40 61/61 [==============================] - 1s 23ms/step - loss: 0.5553 - mse: 0.6199 - rmse: 0.6195 - val_loss: 0.2083 - val_mse: 0.0741 - val_rmse: 0.2398 Epoch 18/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5551 - mse: 0.6194 - rmse: 0.6195 - val_loss: 0.2090 - val_mse: 0.0743 - val_rmse: 0.2400 Epoch 19/40 61/61 [==============================] - 2s 25ms/step - loss: 0.5544 - mse: 0.6189 - rmse: 0.6190 - val_loss: 0.2074 - val_mse: 0.0736 - val_rmse: 0.2383 Epoch 20/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5540 - mse: 0.6186 - rmse: 0.6188 - val_loss: 0.2059 - val_mse: 0.0730 - val_rmse: 0.2366 Epoch 21/40 61/61 [==============================] - 2s 25ms/step - loss: 0.5536 - mse: 0.6181 - rmse: 0.6187 - val_loss: 0.2057 - val_mse: 0.0729 - val_rmse: 0.2361 Epoch 22/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5535 - mse: 0.6182 - rmse: 0.6188 - val_loss: 0.2048 - val_mse: 0.0725 - val_rmse: 0.2351 Epoch 23/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5533 - mse: 0.6179 - rmse: 0.6185 - val_loss: 0.2043 - val_mse: 0.0723 - val_rmse: 0.2344 Epoch 24/40 61/61 [==============================] - 2s 25ms/step - loss: 0.5529 - mse: 0.6175 - rmse: 0.6183 - val_loss: 0.2035 - val_mse: 0.0719 - val_rmse: 0.2334 Epoch 25/40 61/61 [==============================] - 1s 23ms/step - loss: 0.5526 - mse: 0.6173 - rmse: 0.6182 - val_loss: 0.2026 - val_mse: 0.0716 - val_rmse: 0.2325 Epoch 26/40 61/61 [==============================] - 2s 25ms/step - loss: 0.5525 - mse: 0.6171 - rmse: 0.6181 - val_loss: 0.2016 - val_mse: 0.0713 - val_rmse: 0.2315 Epoch 27/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5522 - mse: 0.6171 - rmse: 0.6179 - val_loss: 0.2022 - val_mse: 0.0714 - val_rmse: 0.2316 Epoch 28/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5520 - mse: 0.6168 - rmse: 0.6177 - val_loss: 0.2016 - val_mse: 0.0712 - val_rmse: 0.2309 Epoch 29/40 61/61 [==============================] - 1s 22ms/step - loss: 0.5519 - mse: 0.6166 - rmse: 0.6177 - val_loss: 0.2011 - val_mse: 0.0710 - val_rmse: 0.2303 Epoch 30/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5515 - mse: 0.6162 - rmse: 0.6174 - val_loss: 0.2005 - val_mse: 0.0707 - val_rmse: 0.2295 Epoch 31/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5516 - mse: 0.6164 - rmse: 0.6174 - val_loss: 0.2010 - val_mse: 0.0709 - val_rmse: 0.2297 Epoch 32/40 61/61 [==============================] - 1s 23ms/step - loss: 0.5512 - mse: 0.6156 - rmse: 0.6169 - val_loss: 0.1997 - val_mse: 0.0704 - val_rmse: 0.2284 Epoch 33/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5513 - mse: 0.6161 - rmse: 0.6170 - val_loss: 0.1994 - val_mse: 0.0703 - val_rmse: 0.2280 Epoch 34/40 61/61 [==============================] - 1s 22ms/step - loss: 0.5510 - mse: 0.6157 - rmse: 0.6168 - val_loss: 0.1989 - val_mse: 0.0701 - val_rmse: 0.2274 Epoch 35/40 61/61 [==============================] - 1s 22ms/step - loss: 0.5509 - mse: 0.6156 - rmse: 0.6167 - val_loss: 0.1998 - val_mse: 0.0704 - val_rmse: 0.2280 Epoch 36/40 61/61 [==============================] - 1s 21ms/step - loss: 0.5505 - mse: 0.6147 - rmse: 0.6161 - val_loss: 0.1993 - val_mse: 0.0702 - val_rmse: 0.2272 Epoch 37/40 61/61 [==============================] - 1s 21ms/step - loss: 0.5504 - mse: 0.6148 - rmse: 0.6162 - val_loss: 0.1985 - val_mse: 0.0699 - val_rmse: 0.2265 Epoch 38/40 61/61 [==============================] - 1s 22ms/step - loss: 0.5500 - mse: 0.6141 - rmse: 0.6155 - val_loss: 0.1981 - val_mse: 0.0697 - val_rmse: 0.2259 Epoch 39/40 61/61 [==============================] - 1s 24ms/step - loss: 0.5502 - mse: 0.6150 - rmse: 0.6160 - val_loss: 0.1980 - val_mse: 0.0697 - val_rmse: 0.2257 Epoch 40/40 61/61 [==============================] - 1s 25ms/step - loss: 0.5501 - mse: 0.6141 - rmse: 0.6155 - val_loss: 0.1983 - val_mse: 0.0698 - val_rmse: 0.2257
import matplotlib.pyplot as plt
plt.plot(history.history['loss'], label='MAE Training loss')
plt.plot(history.history['val_loss'], label='MAE Validation loss')
plt.plot(history.history['mse'], label='MSE Training loss')
plt.plot(history.history['val_mse'], label='MSE Validation loss')
plt.plot(history.history['rmse'], label='RMSE Training loss')
plt.plot(history.history['val_rmse'], label='RMSE Validation loss')
plt.legend();
X_train_pred = model.predict(X_train, verbose=0)
train_mae_loss = np.mean(np.abs(X_train_pred - X_train), axis=1)
plt.hist(train_mae_loss, bins=50)
plt.xlabel('Train MAE loss')
plt.ylabel('Number of Samples');
def evaluate_prediction(predictions, actual, model_name):
errors = predictions - actual
mse = np.square(errors).mean()
rmse = np.sqrt(mse)
mae = np.abs(errors).mean()
print(model_name + ':')
print('Mean Absolute Error: {:.4f}'.format(mae))
print('Root Mean Square Error: {:.4f}'.format(rmse))
print('Mean Square Error: {:.4f}'.format(mse))
print('')
return mae,rmse,mse
mae,rmse,mse = evaluate_prediction(X_train_pred, X_train,"LSTM")
LSTM: Mean Absolute Error: 0.2542 Root Mean Square Error: 0.4780 Mean Square Error: 0.2284
model.save(MODELFILENAME+'.h5')
#càlcul del threshold de test
def calculate_threshold(X_test, X_test_pred):
distance = np.sqrt(np.mean(np.square(X_test_pred - X_test),axis=1))
"""Sorting the scores/diffs and using a 0.80 as cutoff value to pick the threshold"""
distance.sort();
cut_off = int(0.9 * len(distance));
threshold = distance[cut_off];
return threshold
for col in columns:
print ("####################### "+col +" ###########################")
#Standardize the test data
scaler = StandardScaler()
test_cpy = test.copy()
test[col] = scaler.fit_transform(test[[col]])
#creem seqüencia amb finestra temporal per les dades de test
X_test1, y_test1 = create_sequences(test[[col]], test[col])
print(f'Testing shape: {X_test1.shape}')
#evaluem el model
eval = model.evaluate(X_test1, y_test1)
print("evaluate: ",eval)
#predim el model
X_test1_pred = model.predict(X_test1, verbose=0)
evaluate_prediction(X_test1_pred, X_test1,"LSTM")
#càlcul del mae_loss
test1_mae_loss = np.mean(np.abs(X_test1_pred - X_test1), axis=1)
test1_rmse_loss = np.sqrt(np.mean(np.square(X_test1_pred - X_test1),axis=1))
# reshaping test prediction
X_test1_predReshape = X_test1_pred.reshape((X_test1_pred.shape[0] * X_test1_pred.shape[1]), X_test1_pred.shape[2])
# reshaping test data
X_test1Reshape = X_test1.reshape((X_test1.shape[0] * X_test1.shape[1]), X_test1.shape[2])
threshold_test = calculate_threshold(X_test1Reshape,X_test1_predReshape)
test1_score_df = pd.DataFrame(test[TIME_STEPS:])
test1_score_df['loss'] = test1_rmse_loss.reshape((-1))
test1_score_df['threshold'] = threshold_test
test1_score_df['anomaly'] = test1_score_df['loss'] > test1_score_df['threshold']
test1_score_df[col] = test[TIME_STEPS:][col]
#gràfic test lost i threshold
fig = go.Figure()
fig.add_trace(go.Scatter(x=test1_score_df.index, y=test1_score_df['loss'], name='Test loss'))
fig.add_trace(go.Scatter(x=test1_score_df.index, y=test1_score_df['threshold'], name='Threshold'))
fig.update_layout(showlegend=True, title='Test loss vs. Threshold')
fig.show()
#Posem les anomalies en un array
anomalies1 = test1_score_df.loc[test1_score_df['anomaly'] == True]
anomalies1.shape
print('anomalies: ',anomalies1.shape); print();
#Gràfic dels punts i de les anomalíes amb els valors de dades transformades per verificar que la normalització que s'ha fet no distorssiona les dades
fig = go.Figure()
fig.add_trace(go.Scatter(x=test1_score_df.index, y=scaler.inverse_transform(test1_score_df[col]), name=col))
fig.add_trace(go.Scatter(x=anomalies1.index, y=scaler.inverse_transform(anomalies1[col]), mode='markers', name='Anomaly'))
fig.update_layout(showlegend=True, title='Detected anomalies')
fig.show()
print ("######################################################")
####################### PM1 ########################### Testing shape: (708, 72, 1) 10/23 [============>.................] - ETA: 0s - loss: 0.5075 - mse: 0.6923 - rmse: 0.5937
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy test[col] = scaler.fit_transform(test[[col]])
23/23 [==============================] - 0s 6ms/step - loss: 0.5918 - mse: 0.8625 - rmse: 0.6866 evaluate: [0.5918375849723816, 0.8625223636627197, 0.686626136302948] LSTM: Mean Absolute Error: 0.2323 Root Mean Square Error: 0.5555 Mean Square Error: 0.3086
anomalies: (287, 10)
###################################################### ####################### PM25 ########################### Testing shape: (708, 72, 1) 10/23 [============>.................] - ETA: 0s - loss: 0.5280 - mse: 0.7211 - rmse: 0.61
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
23/23 [==============================] - 0s 6ms/step - loss: 0.6217 - mse: 0.9282 - rmse: 0.7163 evaluate: [0.621674120426178, 0.9282143115997314, 0.7163441181182861] LSTM: Mean Absolute Error: 0.2464 Root Mean Square Error: 0.5250 Mean Square Error: 0.2756
anomalies: (189, 10)
###################################################### ####################### PM10 ########################### Testing shape: (708, 72, 1) 10/23 [============>.................] - ETA: 0s - loss: 0.5394 - mse: 0.7328 - rmse: 0.6214
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
23/23 [==============================] - 0s 6ms/step - loss: 0.6434 - mse: 0.9737 - rmse: 0.7377 evaluate: [0.6433736681938171, 0.9736828207969666, 0.7377298474311829] LSTM: Mean Absolute Error: 0.2565 Root Mean Square Error: 0.4987 Mean Square Error: 0.2487
anomalies: (107, 10)
###################################################### ####################### PM1ATM ########################### Testing shape: (708, 72, 1) 11/23 [=============>................] - ETA: 0s - loss: 0.5692 - mse: 0.7327 - rmse: 0.66
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
23/23 [==============================] - 0s 6ms/step - loss: 0.6447 - mse: 0.8994 - rmse: 0.7456 evaluate: [0.64466792345047, 0.8994207978248596, 0.7455598711967468] LSTM: Mean Absolute Error: 0.2573 Root Mean Square Error: 0.5070 Mean Square Error: 0.2571
anomalies: (147, 10)
###################################################### ####################### PM25ATM ########################### Testing shape: (708, 72, 1) 1/23 [>.............................] - ETA: 0s - loss: 0.3097 - mse: 0.2634 - rmse: 0.5113
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
23/23 [==============================] - 0s 6ms/step - loss: 0.6383 - mse: 0.8840 - rmse: 0.7381 evaluate: [0.6383222341537476, 0.8840264678001404, 0.7380885481834412] LSTM: Mean Absolute Error: 0.2539 Root Mean Square Error: 0.5127 Mean Square Error: 0.2629
anomalies: (146, 10)
###################################################### ####################### PM10ATM ########################### Testing shape: (708, 72, 1) 10/23 [============>.................] - ETA: 0s - loss: 0.5320 - mse: 0.6930 - rmse: 0.6148
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
23/23 [==============================] - 0s 6ms/step - loss: 0.6313 - mse: 0.8800 - rmse: 0.7254 evaluate: [0.6313465237617493, 0.8799505829811096, 0.7253692150115967] LSTM: Mean Absolute Error: 0.2544 Root Mean Square Error: 0.5137 Mean Square Error: 0.2639
anomalies: (147, 10)
######################################################